/*
public class Test {
    String s;
    public static void main(String[] args) {
         Test test = new Test();
        System.out.println(test.s);
    }
}
*/






/*
class Student{
    public static void hello(){
        System.out.println("hello");
    }
}
public class Test {
    public static void main(String[] args) {
        Student student = null;//null表示此时不指向任何对象，因为静态方法不依赖于对象所以可以编译通过
        student.hello();//hello
    }
}*/







/*
class Student{
    public  void hello(){
        System.out.println("hello");
    }
}
public class Test {
    public static void main(String[] args) {
        Student student = null;//空指针异常
        student.hello();//hello
    }
}*/







/*
class Dog{
    public String name;
    public int age;
    public String color;

    public void eat(){
        System.out.println(this.name + "正在进食");
    }
    public void bark(){
        System.out.println(this.name + "正在吠叫");
    }
}

class Cat{
    public String name;
    public int age;
    public String color;

    public void eat(){
        System.out.println(this.name + "正在进食");
    }
    public void bark(){
        System.out.println(this.name + "正在吠叫");
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.name = "月饼";
        dog.age = 1;
        dog.color = "黄色";
        dog.eat();
        dog.bark();
        System.out.println("=======================");
        Cat cat = new Cat();
        cat.name = "月亮";
        cat.age = 2;
        cat.color = "黑色";
        cat.eat();
        cat.bark();
    }
}
*/








//子类继承父类后达到了代码复用的效果，子类会继承父类中的成员方法和成员变量，但不会继承静态成员方法，静态成员变量。
/*
class Animals{
    public String name;
    public int age;
    public String color;

    public void eat(){
        System.out.println(this.name + "正在进食");
    }
    public void bark(){
        System.out.println(this.name + "正在吠叫");
    }
}
class Dog extends Animals{
    public String sex;
}

class Cat extends Animals{
    public void swap(){
        System.out.println(this.name + "正在摇尾巴");
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.name = "月饼";
        dog.age = 1;
        dog.color = "黄色";
        dog.eat();
        dog.bark();
        System.out.println("=======================");
        Cat cat = new Cat();
        cat.name = "月亮";
        cat.age = 2;
        cat.color = "黑色";
        cat.eat();
        cat.bark();
    }
}
*/







/*
//子类和父类不存在同名成员变量

class Base{
    public int a;
    public int b;
}

class Derived extends Base{
    public int c;

    public void method(){
        a = 10;
        b = 20;
        c = 30;
    }
}
public class Test {
    public static void main(String[] args) {
        Derived derived = new Derived();
        derived.method();
        System.out.println(derived.a);
        System.out.println(derived.b);
        System.out.println(derived.c);
    }
}*/







/*
//子类和父类存在同名成员变量时，局部变量优先

class Base{
    public int a = 2;
    public int b = 5;

}

class Derived extends Base{
    public int c = 4;
    public int a = 1;
    public int b = 2;
    public void method(){
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }
}
public class Test {
    public static void main(String[] args) {
        Derived derived = new Derived();
        derived.method();
    }
}*/








/*//子类和父类存在同名成员变量时，使用super访问父类

class Base{
    public int a = 2;
    public int b = 5;
    public int d = 5;
}

class Derived extends Base{
    public int c = 4;
    public int a = 1;
    public int b = 2;
    public void method(){
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(super.a);//2
        System.out.println(super.b);//5
        System.out.println("=====================");
        System.out.println(this.a);//1
        System.out.println(this.b);//2
        System.out.println(this.c);//4
        System.out.println(this.d);//5
    }
}
public class Test {
    public static void main(String[] args) {
        Derived derived = new Derived();
        derived.method();
    }
}*/








/*class Animals{
    public String name;
    public int age;
    public String color;

    public Animals(){

    }
    public Animals(String name){
        this.name = name;

    }
    public void eat(){
        System.out.println(this.name + "正在进食");
    }
    public void bark(){
        System.out.println(this.name + "正在吠叫");
    }
}
class Dog extends Animals{
    public Dog(){
        super();
    }
    public Dog(String name){
        super(name);
    }
    public String sex;
}


public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
    }
}
*/
